﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Configuration;

namespace TeamNitro.Student
{
    public partial class Students_ContactUs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DBManager_Jowie dbStudent = (DBManager_Jowie)Session["Student"];

            DBManager_Jowie db = DBManager_Jowie.GetStudentInfo(dbStudent.AdminNumber);

            lblName.Text = db.Name;
            lblEmail.Text = db.Email;
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            string from = lblEmail.Text;
            string password = tbxPassword.Text;
            string to = "teamnitro2011@gmail.com";

            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            mail.To.Add(to);
            mail.From = new MailAddress(from, lblName.Text, System.Text.Encoding.UTF8);
            mail.Subject = tbxSubject.Text;
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            mail.Body = EdiContent.Content;
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.IsBodyHtml = true;
            mail.Priority = MailPriority.High;

            SmtpClient client = new SmtpClient();

            client.Credentials = new System.Net.NetworkCredential(from, password);

            client.Port = 587;
            client.Host = "smtp.live.com";
            client.EnableSsl = true;
            try
            {
                client.Send(mail);
                lblResult.Text = "Message Sent Successfully";
                lblResult.ForeColor = System.Drawing.Color.Lime;
                lblResult.Visible = true;
            }
            catch (Exception ex)
            {
                lblResult.Text = "Unable to send message. Please check your email password again.";
                lblResult.ForeColor = System.Drawing.Color.Red;
                lblResult.Visible = true;
            }
        }        
    }
}